Skip to content

fix(platform/tasks): answer 409 when a payment cancel finds the payment settled - #463

Merged
WebCooper merged 2 commits into
OpenNSW:mainfrom
WebCooper:fix/task-api-payment-cancel-409
Dec 3, 2026
Merged

WebCooper merged 2 commits into
OpenNSW:mainfrom
WebCooper:fix/task-api-payment-cancel-409

Conversation

@WebCooper

@WebCooper WebCooper commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What

A cancel that reaches a payment that already settled returned a 500, because the task API did not know the error. It now answers 409 Conflict with the audit code step_conflict.

  • The payment plugin wraps payment.ErrPaymentSettled with orchestrator.ErrStepConflict (added in feat(taskflow): add ErrStepConflict for a plugin that refuses a resume #465). The original error still matches with errors.Is.
  • writeCompletion maps orchestrator.ErrStepConflict to 409, so the task API needs no knowledge of any one plugin's errors.
  • A cancel on a step with no checkout (ErrNoCheckoutToCancel), or for a reference that is not its checkout (ErrTransactionNotFound), is a fault, not a stale view. It stays an ordinary error and answers 500 with an error log.
  • platform now requires the core commit that has ErrStepConflict.

A cancel never completes the step. A caller that gets the 409 should refetch the task.

Why

#452 added the cancel and this error came out of it. The mapping lived in nsw-srilanka's task handler, which moved here in #444, so the 409 was lost.

Testing

TestWriteCompletion_StepConflictIsAConflict covers the sentinel and a manager-wrapped error. The payment Resume tests check that a settled payment matches ErrStepConflict, and that a missing checkout and an unknown reference do not.

Refs OpenNSW/nsw-srilanka#1158

Summary by CodeRabbit

  • Bug Fixes
    • Step conflicts now return an HTTP 409 response with a clear conflict message and are recorded as failed requests.
    • Checkout cancellation errors that are not classified as step conflicts continue to be reported as their specific errors, rather than as conflicts.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The payment task wraps settled-payment cancellation failures with orchestrator.ErrStepConflict. The HTTP handler maps that error to HTTP 409, records a failure audit with code step_conflict, and returns the conflict message.

Changes: Step conflict handling

Layer / File(s) Summary
Classify payment cancellation errors
platform/tasktypes/payment.go, platform/tasktypes/payment_test.go
Resume wraps settled-payment cancellation failures with orchestrator.ErrStepConflict. Tests check whether settled, missing, and unknown checkout errors match the sentinel.
Return and audit step conflicts
platform/go.mod, platform/tasks/http_handler.go, platform/tasks/http_handler_test.go
The github.com/OpenNSW/core dependency is updated. writeCompletion returns HTTP 409 and audits step_conflict for direct or wrapped sentinel errors. Tests verify the response and audit record.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant PaymentTask
  participant TaskHTTPHandler
  participant Audit
  participant Client
  PaymentTask->>TaskHTTPHandler: return step-conflict error
  TaskHTTPHandler->>Audit: record failed update with status 409
  TaskHTTPHandler->>Client: return HTTP 409 conflict response
Loading

Possibly related issues

Possibly related PRs

  • OpenNSW/core#465: Adds the orchestrator.ErrStepConflict sentinel used by the payment task and HTTP handler in this PR.
Merge Risk: Minimal · up to 14682 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a payment cancel that finds the payment settled now returns 409 Conflict. The title matches the summarized changes to writeCompletion, the payment Resume wrapping, and…
Description check Passed The description follows the template. It has a Summary-style 'What' and 'Why' explanation, a Changes list, and a Testing section that names the added tests. It links the related issue in the Refs line…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a payment cancel that finds the payment settled now returns 409 Conflict. The title matches the summarized changes to writeCompletion, the payment Resume wrapping, and the tests. The title is in conventional-commit form and is 79 characters long.

Full details: Description check

Explanation

The description follows the template. It has a Summary-style 'What' and 'Why' explanation, a Changes list, and a Testing section that names the added tests. It links the related issue in the Refs line. It omits the Type of Change checkboxes, the Checklist, and the Screenshots and Additional Notes sections, and it does not mark any testing or checklist items. These are non-critical gaps, so the description is mostly complete.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a8eb4b03-ed1d-4165-8266-a2bab5a56ba0
Commits

Reviewing files that changed from the base of the PR and between 4959471 and 14682e9.

Files ignored due to path filters: 1

  • platform/go.sum is excluded by !**/*.sum
Files selected for processing: 5

  • platform/go.mod
  • platform/tasks/http_handler.go
  • platform/tasks/http_handler_test.go
  • platform/tasktypes/payment.go
  • platform/tasktypes/payment_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@WebCooper WebCooper self-assigned this Dec 2, 2026
@WebCooper
WebCooper marked this pull request as ready for review December 2, 2026 12:44
@WebCooper
WebCooper force-pushed the fix/task-api-payment-cancel-409 branch from 4959471 to 915f38f Compare December 2, 2026 13:14
@WebCooper WebCooper changed the title fix(platform/tasks): map payment cancel errors to 409 fix(platform/tasks): answer 409 when a plugin refuses a resume because the step moved on Dec 2, 2026
Comment thread platform/tasks/http_handler.go Resolved
Comment thread platform/tasktypes/tasktypes.go Resolved
@WebCooper
WebCooper force-pushed the fix/task-api-payment-cancel-409 branch from 915f38f to cf6b648 Compare December 2, 2026 16:48
@WebCooper WebCooper changed the title fix(platform/tasks): answer 409 when a plugin refuses a resume because the step moved on fix(platform/tasks): answer 409 when a payment cancel finds the payment settled Dec 2, 2026
…nt settled

A cancel that reached a payment that had already settled returned a 500
because writeCompletion did not know the error.

The payment plugin wraps payment.ErrPaymentSettled with
orchestrator.ErrStepConflict, and writeCompletion answers any
ErrStepConflict with 409 and the audit code step_conflict, so the task API
needs no knowledge of any one plugin's errors. A cancel on a step with no
checkout, or for a reference that is not its checkout, is a fault and stays
an ordinary error.

Refs OpenNSW/nsw-srilanka#1158
@WebCooper
WebCooper force-pushed the fix/task-api-payment-cancel-409 branch from cf6b648 to 14682e9 Compare December 2, 2026 16:56
@WebCooper
WebCooper marked this pull request as ready for review December 2, 2026 16:57

@sthanikan2000 sthanikan2000 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@WebCooper
WebCooper merged commit 76b6925 into OpenNSW:main Dec 3, 2026
33 checks passed
WebCooper added a commit to WebCooper/nsw-srilanka that referenced this pull request Dec 3, 2026
core/platform 76b6925 answers a cancel for a payment that already settled
with 409 (OpenNSW/core#463), which api/tasks.openapi.yaml documents. It also
moves the core root to 7302004 and, through them, a few indirect modules.

Refs OpenNSW#1158
WebCooper added a commit to WebCooper/nsw-srilanka that referenced this pull request Dec 3, 2026
core/platform 76b6925 answers a cancel for a payment that already settled
with 409 (OpenNSW/core#463), which api/tasks.openapi.yaml documents. It also
moves the core root to 7302004 and, through them, a few indirect modules.

Refs OpenNSW#1158
WebCooper added a commit to WebCooper/nsw-srilanka that referenced this pull request Dec 3, 2026
core/platform 76b6925 answers a cancel for a payment that already settled
with 409 (OpenNSW/core#463), which api/tasks.openapi.yaml documents. It also
moves the core root to 7302004 and, through them, a few indirect modules.

Refs OpenNSW#1158
WebCooper added a commit to WebCooper/nsw-srilanka that referenced this pull request Dec 3, 2026
core/platform 76b6925 answers a cancel for a payment that already settled
with 409 (OpenNSW/core#463), which api/tasks.openapi.yaml documents. It also
moves the core root to 7302004 and, through them, a few indirect modules.

Refs OpenNSW#1158
chathura-de-silva pushed a commit to chathura-de-silva/NSW-SriLanka that referenced this pull request Dec 3, 2026
* docs(tasks): document cancelling a pending payment step

Describe letting the payer choose another method: the artifacts a step
opts in with, and the 409 a cancel gets once the payment has settled.

* build(deps): upgrade core/platform for the 409 on a settled payment

core/platform 76b6925 answers a cancel for a payment that already settled
with 409 (OpenNSW/core#463), which api/tasks.openapi.yaml documents. It also
moves the core root to 7302004 and, through them, a few indirect modules.

Refs OpenNSW#1158
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants